package rensoft.android.rpc.simpleserver;

import static rensoft.java.lang.Lang.is;

import rensoft.android.rpc.IServerRequest;
import rensoft.java.event.Event.EventRegistration;
import rensoft.java.event.Listener;
import rensoft.java.net.UrlBuilder;

public class SessionIdRequestModifier implements Listener<UrlBuilder> {
  private final IServerRequest request;

  public SessionIdRequestModifier(IServerRequest request) {
    this.request = request;
    request.getEventUrlCreate().attach(this);
  }

  @Override
  public void onEvent(EventRegistration registration, UrlBuilder url) {
    if (is(request.getServer().getSessionId()))
      url.add("session", request.getServer().getSessionId());
  }
}
